// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {

  const templateId = 'qdTUREln8-j3g-5j8hx7PFvQqCfj96tsCjz0hObwllY'
  let openid = event.openid
  let name = event.name
  try {
    // console.log("云函数启动")
    const result = await cloud.openapi.subscribeMessage.send({
      touser: openid,
      page: 'pages/index/index',
      lang: 'zh_CN',
      data: {
        thing1: {
          value: 'Maple的大枫树'
        },
        name2: {
          value: name
        },
        phrase3: {
          value: '审核不通过'
        },
        thing4: {
          value: '很抱歉,此次申请未通过'
        },
        thing5: {
          value: 'box未合格或行会已满,感谢您理解与包容'
        }
      },
      templateId: templateId,
      miniprogramState: 'developer'
    })
    // console.log("发送完成")
    // console.log(result)
    return result
  } catch (err) {
    // console.log(err)
    return err
  }
}